<template>
  <div class="lang-selector">
    <el-dropdown @command="handleCommand" trigger="click">
      <span class="el-dropdown-link">
        {{ $t('common.' + currentLang) }} <i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="zh">{{ $t('common.zh') }}</el-dropdown-item>
        <el-dropdown-item command="en">{{ $t('common.en') }}</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
import { setLanguage } from '@/i18n'

export default {
  name: 'LangSelector',
  data() {
    return {
      currentLang: this.$i18n.locale
    }
  },
  methods: {
    handleCommand(lang) {
      if (lang !== this.currentLang) {
        setLanguage(lang)
        this.currentLang = lang
        // 不再刷新页面，使用更平滑的切换方式
      }
    }
  }
}
</script>

<style scoped>
.lang-selector {
  display: inline-block;
  cursor: pointer;
  margin-left: 15px;
}
.el-dropdown-link {
  color: #409EFF;
}
</style> 